package com.sg;


import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;

import com.huawei.hms.push.HmsMessageService;
import com.huawei.hms.push.RemoteMessage;

import org.json.JSONException;
import org.json.JSONObject;

public class DemoHmsMessageService extends HmsMessageService {

    private static final String TAG = "DemoHmsMessageService";

    @Override
    public void onNewToken(String token, Bundle bundle) {
        // 获取token
        Log.i(TAG, "have received refresh token " + token);

        // 判断token是否为空
        if (!TextUtils.isEmpty(token)) {
            refreshedTokenToServer(token);
        }
    }

    private void refreshedTokenToServer(String token) {
        Log.i(TAG, "sending token to server. token:" + token);
    }

    @Override
    public void onMessageReceived(RemoteMessage message) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            //sg:
            Intent in = new Intent("ipush.onNotificationMessageArrived");
            in.putExtra("data", message.getData());
            sendBroadcast(in);

            Log.e("onMessageReceived", message.getData());
            super.onMessageReceived(message);
        }

    }
}
